package server

import (
	v1 "eag_arch_layout/api/baseArch/v1"
	"eag_arch_layout/internal/conf"
	"eag_arch_layout/internal/controller"
	"eag_arch_layout/internal/middleware"

	"github.com/go-kratos/kratos/v2/log"
	"github.com/go-kratos/kratos/v2/transport/http"
)

// NewHTTPServer new an HTTP server.
func NewHTTPServer(c *conf.Server, j *conf.Jwt, sys *controller.SystemController, logger log.Logger) *http.Server {
	//var opts = []http.ServerOption{
	//	http.Middleware(
	//		recovery.Recovery(),
	//	),
	//}
	opts := middleware.CreateMiddleWare(c, j, logger)
	if c.Http.Network != "" {
		opts = append(opts, http.Network(c.Http.Network))
	}
	if c.Http.Addr != "" {
		opts = append(opts, http.Address(c.Http.Addr))
	}
	if c.Http.Timeout != nil {
		opts = append(opts, http.Timeout(c.Http.Timeout.AsDuration()))
	}
	srv := http.NewServer(opts...)
	v1.RegisterSysHTTPServer(srv, sys)
	return srv
}
